//
//  FiveStarImageViewController.m
//  TQY
//
//  Created by 甘世清 on 2024/11/11.
//

#import "FiveStarImageViewController.h"

@interface FiveStarImageViewController ()
@property (nonatomic , strong) SQCustomButton * addButton;
@property (nonatomic , strong) HeaderView * addbtn ;
@end

@implementation FiveStarImageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.zx_navTitle = SQNSLocalString(@"上传截图");
    self.view.backgroundColor = UIColor.whiteColor;
}

- (void)SQ_UIViewForSelfView{
   
    UILabel * label = [[UILabel alloc]init];
    label.text = SQNSLocalString(@"请真实准确的上传好评截图,我们将在24小时内完成审核并发放门票资格!");
    label.textColor = SQColor(@"#333333");
    label.font = FONT_MEDIUM(14);
    label.numberOfLines = 0;
    [self.view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(SCREEN_WIDETH-32);
            make.centerX.equalTo(self.view);
            make.top.equalTo(self.zx_navBar.mas_bottom).offset(20);
    }];
    
    [self.view addSubview:self.addButton];
    [self.addButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(120);
            make.left.equalTo(self.view).offset(16);
        make.top.equalTo(self.zx_navBar.mas_bottom).offset(105);
    }];
    
    self.addbtn = [[HeaderView alloc]init];
    self.addbtn.text = SQNSLocalString(@"提交");
    self.addbtn.font = FONT_SEMIBOLD(16);
    [self.addbtn.btn addTarget:self action:@selector(SQ_addButtonClick) forControlEvents:UIControlEventTouchUpInside];
    self.addbtn.colorString = @"#FFFFFF";
    self.addbtn.backgroundColor = SQColor(@"#BCB0D9");
    self.addbtn.layer.cornerRadius = 25;
    self.addbtn.layer.masksToBounds = YES;
    [self.view addSubview: self.addbtn];
    [ self.addbtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(SCREEN_WIDETH-70);
            make.height.mas_equalTo(50);
            make.centerX.equalTo(self.view);
            make.top.equalTo(self.zx_navBar.mas_bottom).offset(388);
    }];
    [self.view layoutIfNeeded];
    WS(weakSelf);
    [self.addButton setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [weakSelf SQ_rightButtonClick];
    }];
    
}
-(void)SQ_addButtonClick{
    if (self.addButton.SQBackimageView.image ==nil) {
        return;
    }
    WS(weakSelf);
    [YJProgressHUD SQ_showMsgWithoutView:@""];
    [HttpTool SQ_Image:self.addButton.SQBackimageView.image successBlock:^(BaseModel * _Nonnull httpModel) {
        [weakSelf SQ_setUpName:httpModel.data];
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [YJProgressHUD showMsgWithoutView:httpModel.message];
    }];
}
-(void)SQ_setUpName:(NSString*)header{
    if (![header isNotEmpty]) {
        [YJProgressHUD showMsgWithoutView:SQNSLocalString(@"图片上传错误")];
        return;
    }
    WS(weakSelf);
    [YJProgressHUD SQ_showMsgWithoutView:@""];
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:header forKey:@"img"];
    [HttpTool post:@"goodCommentVerify/save" paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        [YJProgressHUD showMsgWithoutView:SQNSLocalString(@"上传成功,我们将在3个工作日内完成审核,请耐心等待!")];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [weakSelf SQ_popViewVC];
        });
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [YJProgressHUD showMsgWithoutView:httpModel.message];
    }];
}

-(void)SQ_rightButtonClick{
    WS(weakSelf);
    TZImagePickerController * vc = [[TZImagePickerController alloc]init];
    vc.maxImagesCount = 1;
    vc.allowPickingVideo = NO;
    vc.scaleAspectFillCrop = NO;
    [[Manager SQ_getCurrentViewController] presentViewController:vc animated:YES completion:nil];
    [vc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
        for (UIImage * image in photos) {
            [weakSelf SQ_caijian:image];
        }
    }];
}
//上传相册
-(void)SQ_caijian:(UIImage*)image {
   
    self.addButton.SQBackimageView.image = image;
    self.addButton.imageView.hidden = YES;
   
    
    self.addbtn.headerImage.image  = SQGetImage(@"bg矩形");
}

- (SQCustomButton *)addButton{
    if (!_addButton) {
        _addButton = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(120, 120) midmargin:0];
        _addButton.image = SQGetImage(@"tianjiatupian");
        _addButton.imageView.contentMode = UIViewContentModeScaleAspectFill;
        _addButton.SQBackimageView.contentMode = UIViewContentModeScaleAspectFill;
        _addButton.clipsToBounds = YES;
        _addButton.layer.cornerRadius = 10;
        _addButton.layer.masksToBounds = YES;
    }
    return _addButton;
}

@end
